import GAMEFUNC_ from "./func.js";

export  default  class CAMERA_CLASS {

    //主相机

    static MAIN_RENDERER(){

    }


    static TICK(runtime){

        if(!GAMEFUNC_.RUNTIME.IN_GAME_LAYOUT(runtime))
        {return}

        this.MAIN_EVENTHANDLER_(runtime)

    }

    static RUNTIME_LAYOUT_START(runtime){
        if(!GAMEFUNC_.RUNTIME.IN_GAME_LAYOUT(runtime))
        {
            return
        }
        CAMERA_CLASS.INIT_EVENTHANDLER(runtime)





    }

    static MAIN_EVENTHANDLER_(runtime){



        CAMERA_CLASS.CAM_FUNCTION.eventhandler(runtime)
        CAMERA_CLASS.CAMERA.moveToTop()
        CAMERA_CLASS.RUNTIME_Z_INDEX.EVENTHANDLER(runtime)






    }


    static INIT_EVENTHANDLER(runtime){


            CAMERA_CLASS.LayerScale=1.5
            CAMERA_CLASS.CAMERA=runtime.objects.camera.getFirstInstance()
            CAMERA_CLASS.CAMERA.opacity=0.1

            CAMERA_CLASS.CAM_BEHAVIORS={
                MOVE_TO:CAMERA_CLASS.CAMERA.behaviors.moveto
            }

    }

    static CAM_FUNCTION={

        eventhandler(runtime){


            this.LERP_CAMER_SCALE(runtime,CAMERA_CLASS.LayerScale)


        },


        LERP_CAMER_SCALE(runtime,endScale){


            let currLayerScale =CAMERA_CLASS.LAYER_FUNC.getLayerScale(runtime)

            //console.log(currLayerScale)

            let lerpValue =GAMEFUNC_.RUNTIME.lerp(runtime,currLayerScale,endScale,0.01)
			



            CAMERA_CLASS.CAM_FUNCTION.setLayerScale(runtime,lerpValue)


        },

        setLayerScale(runtime,scale)
        {
            runtime.callFunction("Camera.SET_LAYOUT_SCALE",scale)
        },

    }


    static MOVEMENT_={

            MOVETOPOS(runtime,x,y){

                    CAMERA_CLASS.CAM_BEHAVIORS.MOVE_TO.moveToPosition(x,y,true)
            }
    }


    static LAYER_FUNC={

        getLayerScale(runtime)
        {
            return runtime.callFunction("getLayerScale")
        }

    }


    static RUNTIME_Z_INDEX={


       EVENTHANDLER(runtime){

        this.ySort(runtime)

           },


        ySort(runtime)
        {
            for(let f_sort of runtime.objects.f_Ysort.instances())
            {
                f_sort.instVars.thisY=f_sort.y

            }

            runtime.sortZOrder(runtime.objects.f_Ysort.instances(),
                (a, b) => a.instVars.thisY - b.instVars.thisY);




        }


    }




}